#include "linkfabric/RingBuffer.hpp"

using namespace linkfabric;

RingBuffer::RingBuffer(size_t cap)
  : buffer_(cap), head_(0), tail_(0), size_(0), capacity_(cap) {}

bool RingBuffer::push(const std::vector<uint8_t>& data) {
    if (isFull()) return false;
    buffer_[tail_] = data;
    tail_ = (tail_ + 1) % capacity_;
    ++size_;
    return true;
}

std::vector<uint8_t> RingBuffer::pop() {
    if (isEmpty()) return {};
    auto out = buffer_[head_];
    head_ = (head_ + 1) % capacity_;
    --size_;
    return out;
}

bool RingBuffer::isEmpty() const { return size_ == 0; }
bool RingBuffer::isFull()  const { return size_ == capacity_; }